import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import commonjs from 'vite-plugin-commonjs';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import path from 'node:path';

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    commonjs(),
    createSvgIconsPlugin({
      iconDirs: [
        path.resolve(__dirname,"src/assets/icons")
      ],
      symbolId:"icon-[name]"
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },

  // 配置代理对象，用于解决跨域。开发环境下挺方便
  server:{
    proxy:{
      '/api':{
        target: 'https://apis.map.qq.com/', //目标源地址，被代理的域名
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''), //自己的接口前缀，代替目标接口的前缀
      }
    }
  }
  
})
